class Solution:
    def sortArrayByParity(self, nums: List[int]) -> List[int]:
        left, right, ans = 0, len(nums) - 1, [0]*  len(nums)
        for num in nums:
            if num % 2 == 0:
                ans[left] = num
                left += 1
            else:
                ans[right] = num
                right -= 1
        return ans